feat: 요청별 로그에 userId MDC 추가 - #211
Conversation
유저 문의/버그 제보 시 특정 유저의 요청·에러 로그를 추적할 수 있도록, JWT에서 userId를 파싱하는 시점에 MDC에 담아 로그 전체에 남긴다.
|
Warning Review limit reached
Next review available in: 49 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe request user ID is stored in SLF4J MDC for visitor and authenticated requests. The filter removes it after request processing. The Logback pattern outputs the MDC user ID with the trace ID. ChangesUser ID logging
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/runnect/server/common/resolver/userId/UserIdResolver.java`:
- Line 80: Move the MDC.put("userId", ...) initialization from
UserIdResolver.resolveArgument into the request-level MdcLoggingFilter or
equivalent interceptor so every request, including handlers without `@UserId`
parameters, has a userId value. Preserve the existing visitor-ID fallback and
ensure the filter sets it before request logging occurs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 41678704-9c9d-4409-ad49-3efa882c7839
📒 Files selected for processing (3)
src/main/java/org/runnect/server/common/resolver/userId/UserIdResolver.javasrc/main/java/org/runnect/server/config/logging/MdcLoggingFilter.javasrc/main/resources/logback-spring.xml
@userid 파라미터가 없는 요청(토큰 재발급, 배너 등)이나 인자 리졸브 이전 단계에서 예외가 나는 경우 userId가 로그에 안 남는 문제를 MdcLoggingFilter에서 accessToken을 미리 파싱해두는 방식으로 보완. 실제 인증 검증/방문자 모드 처리는 UserIdResolver가 그대로 담당하고, 그 결과가 이 값을 덮어쓴다. 로컬 DB/Redis 띄우고 실제 JWT로 검증: - @userid 있는 요청: 요청 진입 로그부터 userId 표시 - @userid 없는 공개 엔드포인트: 토큰만 있으면 userId 표시
배경
유저별 버그 제보 대응 시 해당 유저의 요청/에러 로그를 바로 추적할 수 있도록 userId를 로그에 남김.
변경 사항
UserIdResolver: JWT에서 userId 파싱하는 시점(방문자 모드 포함)에MDC.put("userId", ...)추가MdcLoggingFilter: 요청 종료 시MDC.remove("userId")추가 (스레드 재사용 시 값 누출 방지)logback-spring.xml: 로그 패턴에[userId=%X{userId}]추가활용
배포 후 Grafana Loki에서
{service_name="runnect-server-prod"} | userId="123"로 특정 유저 로그 검색 가능.테스트
Summary by CodeRabbit
New Features
Bug Fixes